<?php
/**
 * @author yuanyitian
 * @date 2023/6/19 20:46
 */

namespace utils;

use OSS\OssClient;
require_once $_SERVER["DOCUMENT_ROOT"]."/global/function.php";
class oss
{
    public static function upload($to_path,$from_path){
        $ossClient = new OssClient($GLOBALS["oss_access_id"], $GLOBALS["oss_access_secret"], $GLOBALS["oss_endpoint"]);
        $res = $ossClient->uploadFile($GLOBALS["oss_bucket"], $to_path, $from_path);
        if(isset($res["info"]["url"])){
            $res["info"]["url"]=str_replace('http://','https://',$res["info"]["url"]);
        }
        return $res;
    }

    public static function delete($path){
        $b="http://".$GLOBALS["oss_bucket"].".".$GLOBALS["oss_endpoint"]."/";
        $path=str_replace($b,null,$path);

        $ossClient = new OssClient($GLOBALS["oss_access_id"], $GLOBALS["oss_access_secret"], $GLOBALS["oss_endpoint"]);
        $res = $ossClient->deleteObject($GLOBALS["oss_bucket"], $path);
        return $res;
    }

}